package xyz.wanwanwan.www.hrm.client.fallback;

import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import xyz.wanwanwan.www.hrm.client.courseclient.RabbitmqClient;
import xyz.wanwanwan.www.hrm.util.AjaxResult;
import xyz.wanwanwan.www.vo.email.SendEmailVo;
import xyz.wanwanwan.www.vo.sms.SendSMSVo;
import xyz.wanwanwan.www.vo.system.SendSystemVo;

@Component
@Slf4j
public class CourseMQFallbackFactory implements FallbackFactory<RabbitmqClient> {
    @Override
    public RabbitmqClient create(Throwable throwable) {
        return new RabbitmqClient() {
            @Override
            public AjaxResult sendSMS(@RequestBody SendSMSVo smsVo) {
                log.error("mq降级，发送短信失败");
                return AjaxResult.me().setSuccess(false).setMessage("mq降级，发送短信失败");
            }

            @Override
            public AjaxResult sendEmail(@RequestBody SendEmailVo emailVo) {
                log.error("mq降级，发送邮件失败");
                return AjaxResult.me().setSuccess(false).setMessage("mq降级，发送邮件失败");
            }

            @Override
            public AjaxResult sendSystem(@RequestBody SendSystemVo systemVo) {
                log.error("mq降级，发送站内信失败");
                return AjaxResult.me().setSuccess(false).setMessage("mq降级，发送站内信失败");
            }
        };
    }
}
